package com.agino.jdk8.learn.annotationlearn.inherited;

import com.agino.jdk8.learn.annotationlearn.inherited.annotation.InheritableMethod;
import com.agino.jdk8.learn.annotationlearn.inherited.annotation.InheritableType;
import com.agino.jdk8.learn.annotationlearn.inherited.testclass.FatherClass;
import com.agino.jdk8.learn.annotationlearn.inherited.testclass.SonClass;
import com.agino.jdk8.learn.utils.PrintUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @author agino
 * @date 2022/4/9 15:10
 **/
public class TestInheritableClass {

    public static void main(String[] args) throws NoSuchMethodException {
        System.out.println(FatherClass.class.isAnnotationPresent(InheritableType.class));

        PrintUtils.printCutOffRule();

        System.out.println(SonClass.class.isAnnotationPresent(InheritableType.class));

        PrintUtils.printCutOffRule();

        // 获取注解上的方法
        Class<FatherClass> fatherClassClass = FatherClass.class;

        Method fatherMethod = fatherClassClass.getMethod("print");

        // 是否包含注解
        System.out.println("FatherClass.class is annotation present InheritableMethod.class：" + fatherMethod.isAnnotationPresent(InheritableMethod.class));

        PrintUtils.printCutOffRule();

        for (Annotation annotation : fatherMethod.getAnnotations()) {
            System.out.println(annotation.annotationType().toGenericString());
        }

        PrintUtils.printCutOffRule();

        // 获取注解上的方法
        Class<SonClass> sonClassClass = SonClass.class;

        Method sonMethod = sonClassClass.getMethod("print");

        // 是否包含注解，只有类上的注解才会继承，方法上不会
        System.out.println("SonClass.class is annotation present InheritableMethod.class：" + sonMethod.isAnnotationPresent(InheritableMethod.class));

        PrintUtils.printCutOffRule();

        for (Annotation annotation : sonMethod.getAnnotations()) {
            System.out.println(annotation.annotationType().toGenericString());
        }


    }
}
